from direct.showbase.DirectObject import DirectObject
from panda3d.core import *

import bullet
import globals

class InputHandler(DirectObject):
    def __init__(self):
        DirectObject.__init__(self)

        # don't use -repeat because of slight delay after keydown
        self.left = False
        self.right = False
        self.up = False
        self.down = False
        self.shot = False
        self.blockshot = False

        #taskMgr.add(self.updateInput, "update input")

    def beginTurnUp(self):
        self.up = True

    def endTurnUp(self):
        self.up = False

    def beginTurnDown(self):
        self.down = True

    def endTurnDown(self):
        self.down = False

    def beginTurnLeft(self):
        self.left = True

    def endTurnLeft(self):
        self.left = False

    def beginTurnRight(self):
        self.right = True

    def endTurnRight(self):
        self.right = False

    def beginShot(self):
        if self.blockshot == False:
            self.shot = True
            self.blockshot = True

    def endShot(self):
        self.shot = False
        self.blockshot = False
        

    def dispatchMessages(self):        
        if self.left:
            messenger.send("left", [1])
        elif self.right:
            messenger.send("right", [-1])

        if self.up:
            messenger.send("up", [1])
        elif self.down:
            messenger.send("down", [-1])

        if self.shot:
            messenger.send("shot")

    def updateInput(self, task):
        return task.cont


            
#            taskMgr.doMethodLater(0.0168, self.setKeySpace, "singleKeyInput")